package com.mall.web.controller.business;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.mall.common.annotation.Log;
import com.mall.common.enums.BusinessType;
import com.mall.business.domain.entity.BusExpressCompany;
import com.mall.business.service.BusExpressCompanyService;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.utils.poi.ExcelUtil;
import com.mall.common.core.page.TableDataInfo;

/**
 * 快递公司Controller
 * 
 * @author zhonglin
 * @date 2020-05-24
 */
@Controller
@RequestMapping("/business/expressCompany")
public class BusExpressCompanyController extends BaseController
{
    private String prefix = "business/expressCompany";

    @Autowired
    private BusExpressCompanyService busExpressCompanyService;

    @RequiresPermissions("business:expressCompany:view")
    @GetMapping()
    public String expressCompany()
    {
        return prefix + "/expressCompany";
    }

    /**
     * 查询快递公司列表
     */
    @RequiresPermissions("business:expressCompany:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BusExpressCompany busExpressCompany)
    {
        startPage();
        List<BusExpressCompany> list = busExpressCompanyService.selectBusExpressCompanyList(busExpressCompany);
        return getDataTable(list);
    }

    /**
     * 导出快递公司列表
     */
    @RequiresPermissions("business:expressCompany:export")
    @Log(title = "快递公司", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BusExpressCompany busExpressCompany)
    {
        List<BusExpressCompany> list = busExpressCompanyService.selectBusExpressCompanyList(busExpressCompany);
        ExcelUtil<BusExpressCompany> util = new ExcelUtil<BusExpressCompany>(BusExpressCompany.class);
        return util.exportExcel(list, "expressCompany");
    }

    /**
     * 新增快递公司
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存快递公司
     */
    @RequiresPermissions("business:expressCompany:add")
    @Log(title = "快递公司", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BusExpressCompany busExpressCompany)
    {
        return toAjax(busExpressCompanyService.insertBusExpressCompany(busExpressCompany));
    }

    /**
     * 修改快递公司
     */
    @GetMapping("/edit/{expressCompanyId}")
    public String edit(@PathVariable("expressCompanyId") Long expressCompanyId, ModelMap mmap)
    {
        BusExpressCompany busExpressCompany = busExpressCompanyService.selectBusExpressCompanyById(expressCompanyId);
        mmap.put("busExpressCompany", busExpressCompany);
        return prefix + "/edit";
    }

    /**
     * 修改保存快递公司
     */
    @RequiresPermissions("business:expressCompany:edit")
    @Log(title = "快递公司", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BusExpressCompany busExpressCompany)
    {
        return toAjax(busExpressCompanyService.updateBusExpressCompany(busExpressCompany));
    }

    /**
     * 删除快递公司
     */
    @RequiresPermissions("business:expressCompany:remove")
    @Log(title = "快递公司", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(busExpressCompanyService.deleteBusExpressCompanyByIds(ids));
    }
}
